package com.runen.wnhz.runen.ui.adapter.puadapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.runen.wnhz.runen.R;
import com.runen.wnhz.runen.data.entity.LessonIntroductionEntity;
import com.runen.wnhz.runen.ui.activity.major.IntroductionActivity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TeachAssistanceRecyclerAdapter extends RecyclerView.Adapter<com.runen.wnhz.runen.ui.adapter.puadapter.TeachAssistanceRecyclerAdapter.ViewHolder> {

    private List<LessonIntroductionEntity.ListBean> listBeanList;
    private Context context;

    public TeachAssistanceRecyclerAdapter(List<LessonIntroductionEntity.ListBean> listBeanList, Context context) {
        this.listBeanList = listBeanList;
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.teach_assistant_layout, null);
        com.runen.wnhz.runen.ui.adapter.puadapter.TeachAssistanceRecyclerAdapter.ViewHolder viewHolder = new com.runen.wnhz.runen.ui.adapter.puadapter.TeachAssistanceRecyclerAdapter.ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final LessonIntroductionEntity.ListBean listBean = listBeanList.get(position);
        Glide.with(context).load(listBean.getPic()).into(holder.image_teachAssistancePic);
        holder.teach_assistanceName.setText(listBean.getTitle());
        holder.linear_teachAssistance.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, IntroductionActivity.class);
                intent.putExtra("pic",listBean.getPic());
                intent.putExtra("lid",listBean.getLid());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        if(listBeanList != null){
            return listBeanList.size();
        }else {
            return 0;
        }
    }


    class ViewHolder extends RecyclerView.ViewHolder  implements View.OnClickListener{

        @BindView(R.id.linear_teachAssistance)
        LinearLayout linear_teachAssistance;
        @BindView(R.id.image_teachAssistancePic)
        ImageView image_teachAssistancePic;
        @BindView(R.id.teach_assistanceName)
        TextView teach_assistanceName;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
            linear_teachAssistance.setOnClickListener(this);
        }

        @Override
        public void onClick(View view) {

        }
    }
}
